home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 347_01.zip / TAVLINIT.C < prev    next >
C/C++ Source or Header  |  1993-04-13  |  2KB  |  52 lines

  1. /*:file:version:date: "%n    V.%v;  %f"
  2.  * "TAVLINIT.C    V.12;  27-Apr-91,12:07:04"
  3.  *
  4.  *  Purpose: Initialize threaded AVL tree. Must be called before tree
  5.  *           can be used.
  6.  *
  7.  *  Released to the PUBLIC DOMAIN
  8.  *
  9.  *               author:    Bert C. Hughes
  10.  *                          200 N.Saratoga
  11.  *                          St.Paul, MN 55104
  12.  *                          Compuserve 71211,577
  13.  */
  14.  
  15. #include "tavlpriv.h"
  16.  
  17. TAVL_treeptr tavl_init(                         /* user supplied functions: */
  18.                      int (*compare)(void *, void *),/* compares identifiers */
  19.                     void *(*key_of)(void *),    /* returns item identifier*/
  20.                     void *(*make_item)(const void *), /* create copy of item */
  21.                     void (*free_item)(void *),      /* frees node's data */
  22.                     void *(*copy_item)(void *, const void *),
  23.                     void *(*alloc)(size_t),
  24.                     void (*dealloc)(void *)
  25.                     )
  26. {
  27.     TAVL_treeptr tree = (*alloc)(sizeof(TAVL_TREE));
  28.  
  29.     if (tree)   {
  30.         if ((tree->head = (*alloc)(sizeof(TAVL_NODE))) != NULL) {
  31.             tree->cmp = compare;
  32.             tree->key_of = key_of;
  33.             tree->make_item = make_item;
  34.             tree->free_item = free_item;
  35.             tree->copy_item = copy_item;
  36.             tree->alloc = alloc;
  37.             tree->dealloc = dealloc;
  38.             tree->head->bf = 0;
  39.             tree->head->Lbit = THREAD;
  40.             tree->head->Rbit = LINK;
  41.             tree->head->dataptr = NULL;
  42.             tree->head->Lptr = tree->head;
  43.             tree->head->Rptr = tree->head;
  44.         }
  45.         else {
  46.             (*dealloc)(tree);
  47.             tree = NULL;
  48.         }
  49.     }
  50.     return tree;
  51. }
  52.